home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: giuliano@ix.netcom.com(Giuliano Carlini)
- Newsgroups: comp.lang.c++
- Subject: Re: Virtual Inheritance
- Date: 8 Apr 1996 08:44:50 GMT
- Organization: Netcom
- Message-ID: <4kajm2$c8m@reader2.ix.netcom.com>
- References: <4k9tpv$173k@news-s01.ny.us.ibm.net>
- NNTP-Posting-Host: lbx-ca6-22.ix.netcom.com
- X-NETCOM-Date: Mon Apr 08 1:44:50 AM PDT 1996
-
- In <4k9tpv$173k@news-s01.ny.us.ibm.net> bbogard@ibm.net writes:
- >what is virtual inheritance? I have used ... VC 4.1 and BC 4.5 and
- >neither of those had virtual inheritance defined in the language.
- >What is it, and what is it used for?
-
- Virtual inheritence is in both VC and BC. Consider the following:
- class Object {
- long id;
- ...
- };
- Where every object in the system is identified by its id, and so
- there must be exactly one id per object. Now consider:
- class Foo : public Object {...};
- class Bar : public Object {...};
- class FooBar: public Foo, Bar {...};
- A foobar has TWO id's. One inherited from foo and the other from
- bar. A memory layout for a foobar would be something like this:
- Foo::Object::id
- Foo::Object::...
- Foo::...
- Bar::Object::id
- Bar::Object::...
- Bar::...
- FooBar::...
- So, how do we tell C++ to give us only one Object in a FooBar? Virtual
- inheritence!
- class Foo : public virtual Object {...};
- class Bar : public virtual Object {...};
- class FooBar: public Foo, Bar {...};
-
- giuliano
-